package ldh.im.business.service;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import ldh.common.PageResult;
import ldh.im.business.dao.CmsLabelDao;
import ldh.im.business.pojo.CmsLabel;
import ldh.im.business.pojo.where.CmsLabelWhere;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: ldh
 * @date: 2021-07-04 17:02:35
*/
@Service("cmsLabelService")
public class CmsLabelService {

	@Resource
	private CmsLabelDao cmsLabelDao;
	
	@Transactional
	public CmsLabel insert(CmsLabel cmsLabel) {
		int n = cmsLabelDao.insert(cmsLabel);
		if (n != 1) {
			throw new RuntimeException("CmsLabel insert error!");
		}
		return cmsLabel;
	}
	
	@Transactional
	public CmsLabel insertSelective(CmsLabel cmsLabel) {
		int n = cmsLabelDao.insert(cmsLabel);
		if (n != 1) {
			throw new RuntimeException("CmsLabel insertSelective error!");
		}
		return cmsLabel;
	}

	@Transactional
	public CmsLabel updateById(CmsLabel cmsLabel) {
		int  n = cmsLabelDao.updateById(cmsLabel);
		if (n != 1) {
			throw new RuntimeException("CmsLabel update error!");
		}
        return cmsLabel;
     }

	@Transactional
	public CmsLabel updateNotNullById(CmsLabel cmsLabel) {
		int  n = cmsLabelDao.updateNotNullById(cmsLabel);
		if (n != 1) {
			throw new RuntimeException("CmsLabel update error!");
		}
        return cmsLabel;
     }


    @Transactional
    public void deleteById(Long id) {
		int n = cmsLabelDao.deleteById(id);
		if (n != 1) {
			throw new RuntimeException("CmsLabel delete error!");
		}
    }

	@Transactional(readOnly = true)
	public CmsLabel getById(Long id) {
		CmsLabel cmsLabel = cmsLabelDao.getById(id);
		return cmsLabel;
    }
    
	
	@Transactional(readOnly = true)
	public PageResult<CmsLabel> findByCmsLabelWhere(CmsLabelWhere cmsLabelWhere) {
		long total = cmsLabelDao.findTotalByCmsLabelWhere(cmsLabelWhere);
		List<CmsLabel> imageList = new ArrayList<CmsLabel>();
		if (total > 0) {
			imageList  = cmsLabelDao.findByCmsLabelWhere(cmsLabelWhere);
		}
		
		return new PageResult<CmsLabel>(cmsLabelWhere, total, imageList);
	}
	
	
}
